<script setup>
import { onMounted } from 'vue'
import { onUnmounted } from 'vue'
import { ref } from 'vue'
import {useRouter} from 'vue-router'

const router = useRouter()

const goHome = () => {
  router.push('/home')
}

const initDate = new Date()

const getTime = () => {
  const date = new Date()
  let h = date.getHours() > 10 ? date.getHours() : `0${date.getHours()}`
  let m = date.getMinutes() > 10 ? date.getMinutes() : `0${date.getMinutes()}`
  let s = date.getSeconds() > 10 ? date.getSeconds() : `0${date.getSeconds()}`
  return `${date.getFullYear()}年${date.getMonth()}月${date.getDay()}日 ${h}:${m}:${s}`
}

// 存储当前时间
let time = ref(`${initDate.getFullYear()}年${initDate.getMonth()}月${initDate.getDay()}日 ${initDate.getHours()}:${initDate.getMinutes()}:${initDate.getSeconds()}`)

// 定时器
let timer = ref(0)

onMounted(() => {
  timer.value = setInterval(() => {
    time.value = getTime()
  }, 1000)
})

onUnmounted(() => {
  clearInterval(timer)
})
</script>

<template>
  <div class="top">
    <div class="left">
      <span class="lbtn" @click="goHome">首页</span>
    </div>
    <div class="center">
      <div class="title">智慧旅游可视化大数据展示平台</div>
    </div>
    <div class="right">
      <span class="rbtn">统计报告</span>
      <span class="time">当前时间: {{time}}</span>
    </div>
  </div>
</template>

<style scoped>
.top {
  display: flex;
  width: 100%;
  height: 40px;
  align-items: center;
  .left {
    flex: 1.5;
    display: flex;
    justify-content: flex-end;
    background: url(../../images/dataScreen-header-left-bg.png) no-repeat;
    background-size: 100% 100%;
    width: 100%;
    height: 40px;
    .lbtn {
      width: 120px;
      height: 45px;
      font-size: 16px;
      text-align: center;
      color: #29fcff;
      line-height: 45px;
      background: url(../../images/dataScreen-header-btn-bg-l.png) no-repeat;
      background-size: 100% 100%;
      cursor: pointer;
    }
  }
  .center {
    flex: 2;
    margin: 0 5px;
    .title {
      height: 130px;
      width: 100%;
      background: url(../../images/dataScreen-header-center-bg.png) no-repeat;
      background-size: 100% 100%;
      text-align: center;
      font-size: 30px;
      color: #29fcff;
      line-height: 170px;
      overflow: hidden;
    }
  }
  .right {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1.5;
    background: url(../../images/dataScreen-header-right-bg.png) no-repeat;
    background-size: 100% 100%;
    width: 100%;
    height: 40px;
    .rbtn {
      margin-top: 5px;
      width: 120px;
      height: 45px;
      font-size: 16px;
      text-align: center;
      color: #29fcff;
      line-height: 40px;
      background: url(../../images/dataScreen-header-btn-bg-r.png) no-repeat;
      background-size: 100% 100%;
    }
    .time {
      color: #29fcff;
      margin-right: 100px;
      font-size: 16px;
    }
  }
}
</style>
